package programmercarl.动态规划.C16;

class Solution {
    int count=0;
    public int findTargetSumWays(int[] nums, int target) {
        //回溯
        backTrack(nums,target,0,0);
        return count;
    }

    public void backTrack(int[] nums, int target, int index, int sum) {
        if (index == nums.length) {
            if (sum == target) {
                count++;
            }
        }else {
            backTrack(nums, target, index+1, sum+nums[index]);//+上一个值
            backTrack(nums, target, index+1, sum-nums[index]);//减去一个值
        }
    }
}